<script>
import * as AuthAction from '@/api/auth'
const updateManager = wx.getUpdateManager()
export default {
  created () {
    this.checkLogin()
  },
  onShow () {
    updateManager.onCheckForUpdate(function (res) {
      if (res.hasUpdate) {
        wx.showLoading({
          title: '版本更新中...',
          mask: true
        })
      }
    })
    updateManager.onUpdateReady(function () {
      wx.hideLoading()
      wx.showModal({
        title: '更新提示',
        content: '新版本已经准备好，是否重启应用？',
        showCancel: false,
        success (res) {
          if (res.confirm) updateManager.applyUpdate()
        },
        fail: console.error
      })
    })
  },
  methods: {
    checkLogin () {
      let that = this
      wx.login({
        success: res => {
          if (res.code) {
            AuthAction.mpLogin(res.code)
              .then(data => {
                if (data.me) {
                  that.$store.commit('set_me', data.me)
                  wx.setStorageSync('token', data.token)
                } else { wx.setStorageSync('openid', data.openid) }
              }).catch(err => console.log(err))
          } else { console.log(res) }
        },
        fail: console.error
      })
    }
  }
}
</script>

<style lang="less">
@theme-red: #ED6D96;
page {
  width: 100%;
  overflow-y: auto !important;
  overflow: hidden;
}
.container {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch; // 优化ios下的惯性滚动
  button::after {
    border: none;
  }
  .pro-list {
    padding: 0 25rpx;
    .pro-item {
      background: #fff;
      overflow: hidden;
      margin-top: 15rpx;
      .pro-pic {
        width: 100%;
        height: 345rpx;
        border-radius: 4rpx;
      }
      .info {
        margin: 0 20rpx;
        .desc {
          color: #333;
          font-size: 24rpx;
          height: 65rpx;
          overflow: hidden;
          margin: 10rpx 0;
        }
        .price {
          color: @theme-red;
          font-size: 28rpx;
        }
      }
    }
  }
}
  .address-item {
    width: 100%;
    display: flex;
    .title {
     width:90px;
      text-align:left;
      color:#333333;
    }
    .value {
      flex:1;
      text-align:left;
    }
  }
// 覆盖默认按钮样式为主题色
.mk-button {
  .van-button--primary {
    background-color: @theme-red;
    border: 1px solid @theme-red;
    border-radius:10rpx;
    margin-bottom: 15rpx;
  }
  .van-button--default {
    border: 1px solid #353535;
    color: #353535;
  }
  .van-button--plain {
    &.van-button--primary {
      color: @theme-red;
      background-color: #ffffff;
      border-radius:10rpx;
    }
  }
}
// 登录入口按钮样式
.mk-login-button {
  .van-button--primary {
    background-color: @theme-red;
    border:2rpx solid  @theme-red;
    color:#ffffff;
    margin:26rpx 0;
    font-size: 26rpx;
    border-radius:10rpx;
  }
    .van-button--plain {
    &.van-button--primary {
      color:  @theme-red;
      margin:26rpx 0;
      font-size: 26rpx;
    border-radius:10rpx;
      background-color: #ffffff;
      border:2rpx solid  @theme-red;
    }
  }
}
// 订单提交栏目样式
.mk-submit-bar {
  .van-submit-bar__bar--safe {
    padding-bottom: 0;
  }
  .van-submit-bar__bar {
    height: 46px;
    font-size: 15px;
  }
  .van-button {
    background-color: @theme-red;
    border-color: @theme-red;
    height: 44px;
    line-height: 44px;
    font-size: 16px;
  }
}
// 商品详情栏目样式
.mk-goods-action {
    .van-submit-bar__bar--safe {
    padding-bottom: 0;
  }
  .van-button {
    height: 46px;
    line-height: 46px;
    font-size: 15px;
  }
  .van-button--danger {
    background-color: @theme-red;
    border-color: @theme-red;
  }
  .van-button--warning {
    background-color: #f28dac;
    border-color: #f28dac;
  }
  .van-icon {
    font-size: 16px !important;
  }
}
.mk-van-search {
  .van-cell {
    border-radius: 28rpx;
  }
}

</style>
